package com.bjpowernode.core.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bjpowernode.DlykServerApplication;
import com.bjpowernode.common.constant.DicEnum;
import com.bjpowernode.entity.TDicValue;

import java.util.List;

public class SourceConverter implements Converter<Integer> {
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {

        String excelValue = cellData.getStringValue();

        List<TDicValue> dicValueList = (List<TDicValue>) DlykServerApplication.cacheMap.get(DicEnum.SOURCE.getCode());

        for (TDicValue dicValue : dicValueList) {
            String typeValue = dicValue.getTypeValue();
            if (typeValue.equals(excelValue)) {
                return dicValue.getId();
            }
        }
        throw new RuntimeException("字典值不存在，请修改Excel");


    }
}
